//
//  CommentTableViewCell.m
//  Supervisor
//
//  Created by 小宇 on 2017/5/12.
//  Copyright © 2017年 北京怀教网络科技股份有限公司. All rights reserved.
//

#import "CommentTableViewCell.h"
#import "UIView+RectCorner.h"

@interface CommentTableViewCell()
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)UILabel *timeLabel;

@end
@implementation CommentTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
 {
     static NSString *identifier = @"QuotedSupervisor";
     // 1.缓存中取
     CommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
     // 2.创建
     if (cell == nil) {
         cell = [[CommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier showState:NO];
     }
    return cell;
}

+ (instancetype)cellWithNoticeTableView:(UITableView *)tableView {
    static NSString *identifier = @"notice";
    // 1.缓存中取
    CommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[CommentTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier showState:YES];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier showState:(BOOL)showstate
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat titleLabelWith = Main_Screen_Width - 33;
        CGFloat titleLabelX = 11;
        if (showstate) {
            titleLabelWith = Main_Screen_Width - 70;
            titleLabelX = 15;
        }
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabelX, 16.5, titleLabelWith, 21) Text:nil TextColor:GeneralFontColor TextAlignment:NSTextAlignmentLeft Font:AdaptedFontSize(15) Target:nil Action:nil];
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(titleLabelX, CGRectGetMaxY(self.titleLabel.frame) + 14, Main_Screen_Width - 33, 16.5) Text:nil TextColor:[UIColor colorWithHexString:@"#999999"] TextAlignment:NSTextAlignmentLeft Font:AdaptedFontSize(12) Target:nil Action:nil];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 82.5, Main_Screen_Width, 0.5)];
        lineView.backgroundColor = LineColor;
        if (showstate) {
        self.tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(Main_Screen_Width - 55, 16.5, 40, 21) Text:@"未读" TextColor:[UIColor colorWithHexString:@"#FFFFFF"] TextAlignment:NSTextAlignmentCenter Font:AdaptedFontSize(12) Target:nil Action:nil];
        self.tipLabel.backgroundColor = [UIColor colorWithHexString:@"#F65A5A"];
        [self.tipLabel setAllCornerWithCornerRadius:4];
        [self.contentView addSubview:self.tipLabel];
        }
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:lineView];
    }
    return self;
}

- (void)settingWithSupecailModel:(QuotedSupervisorGC *)model{
    self.titleLabel.text = model.title;
    self.timeLabel.text = model.ename;
}

- (void)settingWithModel:(QuotedSupervisorGC *)model{
    self.titleLabel.text = [NSString removeSpaceAndNewline:[NSString filterHTML:model.plantxt]];
    if (model.content) {
        self.titleLabel.text = [NSString removeSpaceAndNewline:[NSString filterHTML:model.content]];
    }
    self.timeLabel.text = [model.createTime substringToIndex:10];
}

- (void)settingWithNoticeModel:(NoticeModel *)model{
    self.titleLabel.text = model.title;
    self.timeLabel.text = [NSString stringWithFormat:@"%@ %@",model.sendername,[model.createTime substringToIndex:16]];
    self.tipLabel.hidden = model.state;
}


@end
